package com.softwinner.bt;

import com.softwinner.bt.util.Command;
import com.softwinner.bt.util.Utils;
import com.softwinner.bt.util.BTLog;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class InComingDialog extends BaseActivity {
    private ImageView handupButton;
    private String phoneName;
    private TextView phoneNameV;
    private String phoneNum = null;
    private TextView phoneNumV = null;
    private ImageView pickupButton = null;
    public static boolean isCall = false;
    
    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.bt_incoming);    
        isCall = true;
        Bundle localBundle = getIntent().getExtras();
        this.phoneNum = localBundle.getString("phoneNum");
        try {
        	this.phoneName = getName(this.phoneNum);
		} catch (Exception e) {}
        this.phoneNameV = ((TextView) findViewById(R.id.bt_income_name));
        this.phoneNumV = ((TextView) findViewById(R.id.bt_income_num));
        this.phoneNameV.setText(this.phoneName);
        this.phoneNumV.setText(this.phoneNum);
        this.handupButton = ((ImageView) findViewById(R.id.bt_income_hangup));
        this.handupButton.setOnClickListener(this);
        this.pickupButton = ((ImageView) findViewById(R.id.bt_income_dialer));
        this.pickupButton.setOnClickListener(this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        return super.onKeyDown(keyCode, event);
    }

    protected void onPause() {
        super.onPause();
    }

    protected void onResume() {
        super.onResume();
    }
    @Override
    public void onClick(View vew) {
        switch (vew.getId()) {
        case R.id.bt_income_dialer:
            mBTManager
                    .sendCommand(Command.SEND_ANSWER);
            finish();
            break;
        case R.id.bt_income_hangup:
            mBTManager.sendCommand(Command.SEND_REFUSE);
            finish();
            break;
        default:
            break;
        }
    }

	@Override
	protected void phoneStateChanged(String action) {
		// TODO Auto-generated method stub
		if(action.equals(Utils.ACTION_PHONE_INCALL)){
			finish();
		}
	}
	
	@Override
	protected void onDestroy(){
		// TODO Auto-generated method stub
		BTLog.i(this.getClass(), "onDestroy()");
		isCall = false;
		super.onDestroy();
	}
}
